<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="com.gj.bean.*,com.gj.dao.*,com.gj.daoImp.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../css/main.css" type="text/css" rel="stylesheet"/>
</head>
<body style="margin: 0px auto; border: 0px" >

 <%
	request.setCharacterEncoding("UTF-8");
	ArrayList<ContactsBean> contacts=new ArrayList<ContactsBean>();
ArrayList<CategoryBean> category=new ArrayList<CategoryBean>();
 
 UserBean user =(UserBean) session.getAttribute("user"); 
	ContactDao bookMng = new ContactDaoImp();
	CategoryDao categoryManage= new CategoryDaoImp(); 
	/*  category=(ArrayList<CategoryBean>)request.getAttribute("category");
	 contacts=(ArrayList<ContactsBean>)request.getAttribute("Allcontacts"); */
	  //管理员
	  	System.out.println(user.getUserId());
	if(user.getUserRole()==0){
		  category=categoryManage.GetCategoryInfo(); 
		  String type = request.getParameter("relation");
		 	if(type==null){
		 		contacts =bookMng.getContactInfo();  
		 	}
		 	 else{
		 	    
		 	   int categoryId=Integer.parseInt(request.getParameter("categoryId"));
		 		out.println(request.getParameter("categoryId"));
		 		contacts =bookMng.getContactInfoBygroup(categoryId);
		 	}		 	 
	}
	//普通用户
	if(user.getUserRole()==1){ 
		String type = request.getParameter("relation");
		 category=categoryManage.GetCategoryInfo();//分组
		 if(type==null){
			 
			 contacts =bookMng.findContacts(user.getUserId());  //联系人列表
		
	 	}
		 else{
			 int categoryId=Integer.parseInt(request.getParameter("categoryId"));
		 		contacts =bookMng.getContactInfoBygroup(categoryId);

		 }
	}  
%>  

   		<!-- <div class="kuan"><input name="" type="text" /></div>搜索框
        <div class="an"><input name="" type="button" value=搜索 /></div>搜索按钮 -->
    <div id="wrap">  
        <div id="header">个人通讯录</div>  
        <div id="container">  
            <div id="left_side">
          		<%for(CategoryBean relation:category) {%>
          			
          			<div id="relation">
            			<a  href="mainPage.jsp?categoryId=<%=relation.getCategoryId()%>&relation=group"><%=relation.getCategoryName()%></a>
            		
            	     </div>
            	
          		<%}%>
            	
         
            	
           </div>  
  <div id="content">
            	<table  border="0" cellspacing="0" cellpadding="0"  width="500" >
		  <thead>
				<tr>
					<th>姓名</th>
					<th>电话</th>
					<th>备注</th>
				</tr>
		 </thead>
		<tbody>
		<%
		
		for(ContactsBean book:contacts){ %>
			<tr>
			    <td><%=book.getContactName() %></td>
				<td><%=book.getContectNum() %></td>
				<td><%=book.getMark() %></td>	
				<td><a href="ContactServlet?contactId=<%=book.getContactId()%>&type=del">删除</a></td>	
				<td><a href="contactDetail.jsp?contactId=<%=book.getContactId() %>">查看详情</a></td>	
		<tr>
	<% 	}

	%>
		
            </tbody>
		 
	</table>
            </div>  
            <div id="right_side">
            
            	<div><a href="mainPage.jsp" style="background-image: ">首页</a></div>
            	<div><a href="AddContact.jsp" style="background-image: ">增加</a></div>
            	<div><a href="mainPage.jsp" style="background-image: ">查找</a></div>
            	<div><a href="NewLogin.jsp" style="background-image: ">退出</a></div>
            	
          		
			</div>  
        </div>  
    </div>  
</body>
</html>